#include <raylib.h>
#include <stdio.h>

int player(int argc,char **argv);

int main(int argc,char **argv){
    return player(argc,argv);
}

int player(int argc,char **argv){
    InitAudioDevice();
    InitWindow(800, 600, "凤凰传奇-奢香夫人");
    SetWindowIcon(LoadImage("resource/icon.png"));
    char * path = "resource/fhcq.mp3";
    char textbuff[1024] = {'\0'};
    Music mus = LoadMusicStream(path);
    PlayMusicStream(mus);
    float len = GetMusicTimeLength(mus);
    // float len = 10;
    float stp = len * 0.02;
    float now = 0;
    SetTargetFPS(60);
    Vector2 mp = {0,0};
    // perror("eeeee\n");
    while (!WindowShouldClose()) {
        mp = GetMousePosition();
        if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
            SeekMusicStream(mus, 0.0);
        }
        if(IsKeyPressed(KEY_RIGHT)){
            SeekMusicStream(mus, now+stp);
        }
        if (IsKeyPressed(KEY_LEFT)) {
            SeekMusicStream(mus, (now>stp)?now-stp:0);
        }
        UpdateMusicStream(mus);
        now = GetMusicTimePlayed(mus);
        BeginDrawing();
        ClearBackground(WHITE);
        sprintf(textbuff,"%.2f/%.2f", now,len);
        DrawText(textbuff, 100, 100, 24, BLACK);
        sprintf(textbuff,"x:%d,y:%d",(int)mp.x,(int)mp.y);
        DrawText(textbuff, 0, 0, 24, BLACK);
        DrawLine(0, mp.y, 800, mp.y, BLACK);
        DrawLine(mp.x, 0, mp.x, 600, BLACK);
        DrawLine(0, 1, 800,1, BLACK);
        EndDrawing();
    }
    UnloadMusicStream(mus);
    CloseWindow();
    CloseAudioDevice();
    return 0;
}
